﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Microsoft.ApplicationBlocks.Data;

namespace DanhMuc
{
    class CongViecInfo
    {
        private string _CongViecID;

        public string CongViecID
        {
            get { return _CongViecID; }
            set { _CongViecID = value; }
        }

        private string _TenCongViec;

        public string TenCongViec
        {
            get { return _TenCongViec; }
            set { _TenCongViec = value; }
        }
        private bool _Active;

        public bool Active
        {
            get { return _Active; }
            set { _Active = value; }
        }
    }

    class CongViecCtr
    {
        string strCnn = DBClass_FANIT82.GetConnectString();

        public void Insert(CongViecInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@CongViecID", Item.CongViecID),
                new SqlParameter("@TenCongViec", Item.TenCongViec == null ? (object)DBNull.Value:Item.TenCongViec),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_CongViec_Insert", Para);
        }

        public void Update(CongViecInfo Item)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@CongViecID", Item.CongViecID),
                new SqlParameter("@TenCongViec", Item.TenCongViec == null ? (object)DBNull.Value:Item.TenCongViec),
                new SqlParameter("@Active", Item.Active == null ? (object)DBNull.Value:Item.Active)
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_CongViec_Update", Para);
        }

        public void Delete(string strCongViecID)
        {
            SqlParameter[] Para = new SqlParameter[]
            {
                new SqlParameter("@CongViecID", strCongViecID),
            };
            SqlHelper.ExecuteNonQuery(strCnn, CommandType.StoredProcedure, "D_CongViec_Delete", Para);
        }

        public DataTable GetList()
        {
            DataSet Ds = SqlHelper.ExecuteDataset(strCnn, CommandType.StoredProcedure, "D_CongViec_GetList");
            return Ds.Tables[0];
        }

        public CongViecInfo GetByID(string strCongViecID)
        {
            SqlDataReader dtr = SqlHelper.ExecuteReader(strCnn, CommandType.StoredProcedure, "D_CongViec_Get", new SqlParameter("CongViecID", strCongViecID));
            CongViecInfo ObjCongViec = null;
            while (dtr.Read())
            {
                ObjCongViec = new CongViecInfo();
                ObjCongViec.CongViecID = dtr["CongViecID"].ToString();
                ObjCongViec.TenCongViec = dtr["TenCongViec"].ToString();
                ObjCongViec.Active = (bool)dtr["Active"];
            }
            return ObjCongViec;
        }
    }
}
